package com.stars.services.impl.system;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.stars.dao.mapper.system.SysUrlsMapper;
import com.stars.entity.ListPage;
import com.stars.entity.dto.system.SysUrlsDTO;
import com.stars.entity.system.SysUrlsEntity;
import com.stars.services.impl.BaseAccessServiceImpl;
import com.stars.services.system.SysUrlsAccessServices;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author dj
 * @version V1.0
 * @Title: 系统所有URL管理表 业务逻辑
 * @date 2019-10-21 12:43:35
 */
@Service
public class SysUrlsAccessServicesImpl extends BaseAccessServiceImpl<SysUrlsMapper, SysUrlsEntity> implements SysUrlsAccessServices {
    @Autowired
    private SysUrlsMapper sysUrlsMapper;
    /**
     * 分页查询
     *
     * @param pageNum 查询参数 起始页，大小。
     * @return
     */
    @Override
    public PageInfo<SysUrlsDTO> pageList(Integer pageNum, Integer pageSize, SysUrlsDTO dto) throws Exception {
        ListPage<SysUrlsDTO> listPage = new ListPage<>(pageNum, pageSize, dto);
        PageHelper.startPage(pageNum, pageSize);
        List<SysUrlsDTO> list = new ArrayList<>();
        if (StringUtils.isNotBlank(dto.getMenuId())) {
            list = sysUrlsMapper.pageQueryByMenuId(listPage);
        } else {
            list = sysUrlsMapper.pageQuerySysUrls(listPage);
        }
        PageInfo<SysUrlsDTO> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public List<SysUrlsDTO> findUrlByUrl(String url) throws Exception {
        if(StringUtils.isBlank(url)) {
            return null;
        }
        List<SysUrlsDTO> list = sysUrlsMapper.queryListByUrl(url);
        return list;
    }
}
